package com.hysf.dao.impl;

import com.hysf.dao.BaseDao;
import com.hysf.dao.UserDao;
import com.hysf.entity.User;

import java.util.List;

public class UserDaoImpl extends BaseDao implements UserDao {
    /**
     *
     * @Description:
     *
     * @Author: 石涛
     * @Date: 2024/4/9 10:51
     **/
    @Override
    public User queryUserByUsername(String username) {
        String sql = "select * from user where username = ?";
        return queryByOne(User.class, sql, username);
    }
    /**
     *
     * @Description:
     *
     * @Author: 石涛
     * @Date: 2024/4/9 10:51
     **/
    @Override
    public User queryUserByUsernameAndPassword(String username, String password) {
        String sql = "select * from user where username = ? and password = ? ";
        return queryByOne(User.class, sql, username, password);
    }
    /**
     *
     * @Description:
     *
     * @Author: 石涛
     * @Date: 2024/4/9 10:51
     **/
    @Override
    public int saveUser(User user) {
        String sql = "insert into user (username, password,email,gender,hobby,createTime,state) values(?,?,?,?,?,?,?)";
        return update(sql,
                user.getUsername(),
                user.getPassword(),
                user.getEmail(),
                user.getGender(),
                user.getHobby(),
                user.getCreateTime(),
                user.getState());

    }
    /**
     *
     * @Description:
     *
     * @Author: 石涛
     * @Date: 2024/4/9 10:51
     **/
    @Override
    public User queryUserByUP(String username, String password) {
        String sql = "select * from user where username = ? and password = ? ";
        return queryByOne(User.class, sql, username, password);
    }
    /**
     *
     * @Description:
     *
     * @Author: 石涛
     * @Date: 2024/4/9 10:51
     **/
    @Override
    public List<User> existsUP(String username) {
        // 构造SQL语句，使用占位符?来代表pid的值
        String sql = "select * from user where username = ? ";
        // 创建一个包含pid值的Object数组，用于传递给queryByList方法
        Object[] params = new Object[]{username};
        // 调用queryByList方法，并传入Product.class作为类型参数，以及SQL语句和参数数组
        return queryByList(User.class, sql, params);
    }
}
